<style>
    .layui-btn .layui-icon{
        margin-right: 0;
    }
    .layui-layer-page .layui-layer-content{
        overflow: initial;
    }
</style>
<form class="layui-form seller-form" action="">
<div class="layui-form-item">
	<div class="layui-inline">
		<label class="layui-form-label">入库单号：</label>
		<!-- <div class="layui-input-inline seller-inline-3"> -->
		<div class="layui-input-inline">
			<input type="text" name="id" placeholder="请输入入库单号" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-inline">
		<label class="layui-form-label">时间：</label>
		<div class="layui-input-inline">
			<input type="text" name="date" id="date" placeholder="开始时间 到 结束时间" autocomplete="off"
				   class="layui-input">
		</div>
	</div>
	<div class="layui-inline" id="layui-btn-group-container">
		<button class="layui-btn layui-btn-sm" lay-submit lay-filter="*"><i
				class="iconfont icon-chaxun"></i>筛选</button>

		<button class="layui-btn add-class layui-btn-sm"><i class="layui-icon">&#xe608;</i> 添加</button>
	</div>

</div>
</form>
<div class="table-body">
	<table id="hbTable" lay-filter="test"></table>
</div>
<script>
    var table;
    layui.use(['form', 'layedit', 'laydate','table'], function(){
        var form = layui.form;
//时间插件
		layui.laydate.render({
			elem: '#date',
			range: '到',
			format: 'yyyy-MM-dd',
			trigger: 'click' //自动弹出控件的事件，采用click弹出
		});
        table = layui.table.render({
            elem: '#hbTable',
            height: 'full-99',
            cellMinWidth: '80',
            page: 'true',
            limit:'20',
            url: "{:get_addon_url('StockControl://index/stock1index')}?_ajax=1",
            id:'hbTable',
            cols: [[
				{field:'id', width:200, title:'入库单号', align: 'center'},
				{field:'username', width:200, title:'操作人', align: 'center'},
				{field:'memo',title:'备注', align: 'center'},
				{field:'ctime', width:200,title:'入库时间', align: 'center'},

                {field:'operating',title:'操作',templet:function(data){
                    var html = '<a  class="layui-btn layui-btn-xs option-view" data-id="' + data.id + '">查看详情</a>';
                    return html;
                }, align: 'center', width: 140}
            ]]
        });
        layui.form.on('submit(*)', function(data){
            layui.table.reload('hbTable', {
                where: data.field
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


        //添加
        $(document).on('click', '.add-class', function(){
            JsGet("{:get_addon_url('StockControl://index/stock1Add')}", function(tpl){
				if(tpl.status){
					layer.open({
						type: 1,
						area: setpage(800,500),
						data:'',
						title: '新增入库单',
						content: tpl.data,
						btn:['保存','关闭'],
						yes:function (index,layero) {
							var data1 = form.val("stock1");
							JsPost("{:get_addon_url('StockControl://index/stock1Add')}",data1,function (re) {
								if(re.status){
									layer.msg('保存成功');
									layer.close(index);
									//userTables.reload();
									layui.table.reload('hbTable');
								}else{
									layer.msg(re.msg);
								}
							});
						}
					});
				}else{
					layer.msg(tpl.msg);
				}
			});
            return false;
        });
        //查看详情
		$(document).on('click', '.option-view', function(){
			var id = $(this).attr('data-id');
			JsGet("{:get_addon_url('StockControl://index/stockView')}?id="+id+"&type="+1, function(tpl){
				if(tpl.status){
					layer.open({
						type: 1,
						area: setpage(700,600),
						data:'',
						title: '查看入库单详情',
						content: tpl.data,
						// btn:['关闭'],

					});
				}else{
					layer.msg(tpl.msg);
				}
			});
			return false;
		});

    });



</script>